<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title>玄晏先生代理管理系统 - 登录</title>
    <meta name="keywords" content="玄晏先生">
    <meta name="description" content="玄晏先生">
    
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/plugins/ztree/style.css" rel="stylesheet">
    <link href="css/login.css" rel="stylesheet">
    <style type="text/css">

        .login-form .account-control label {
            /*margin-left: 24px;*/
            font-size: 12px;
            font-family: Arial, Helvetica, sans-serif;
            cursor: pointer;
        }
        .login-form .account-control input {
            width: 0px;
            height: 0px;
        }

        .login-form label.check {
            /*position: absolute;*/
            left: 0;
            top: 50%;
            margin: -8px 0;
            display: inline-block;
            width: 16px;
            height: 16px;
            line-height: 16px;
            text-align: center;
            border-radius: 2px;
            background: -webkit-linear-gradient(top, rgb(255, 255, 255), rgb(246, 246, 246)) 1px 1px no-repeat,
            -webkit-linear-gradient(top, rgb(227, 227, 230), rgb(165, 165, 165)) left top no-repeat;
            background-size: 14px 14px, 16px 16px;
        }

        .login-form .account-control input:checked + label.check:before {
            content: attr(data-on);
            color: black;
            font-family: loginform-icon;
        }

        @font-face {
            font-family: 'loginform-icon';
            src: url("fonts/font/loginform-icon.eot");
            src: url("fonts/font/loginform-icon.eot?#iefix") format('embedded-opentype'),
            url("fonts/font/loginform-icon.woff") format('woff'),
            url("fonts/font/loginform-icon.ttf") format('truetype'),
            url("fonts/font/loginform-icon.svg#loginform-icon") format('svg');
            font-weight: normal;
            font-style: normal;
        }
    
    </style>
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>

</head>

<body class="signin">
    <div class="signinpanel">
        <div class="row">
            <div class="col-sm-7">
                <div class="signin-info">
                    <div class="logopanel m-b">
                        <h1></h1>
                    </div>
                    <div class="m-b"></div>
                    <h4>欢迎使用 <strong>玄晏先生代理管理系统</strong></h4>
                </div>
            </div>
            <div class="col-sm-5">
                <form method="post" class="login-form" action="">
                    <h4 class="no-margins">登录：</h4>
                    <p class="m-t-md">登录到管理系统</p>
                    <input type="text" id ="soft_username" class="form-control uname" placeholder="用户名" />
                    <input type="password" id="soft_password" class="form-control pword m-b" placeholder="密码" />
                    <div class="account-control">

                        <input type="checkbox" id="remember" style="display:none;">
                        <label for="remember" id="checkRememberId" data-on="c" class="check"></label>
                        <label for="remember" class="info">记住我</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="">忘记密码了？</a> 
                    </div>
                    <button id="login" class="btn btn-success btn-block" type="button">登录</button>
                </form>
            </div>
        </div>
        <div class="signup-footer">
            <div class="pull-left">
                &copy; 2017 All Rights Reserved. H+
            </div>
        </div>
    </div>
</body>
<!-- 全局js -->
<script src="../../js/jquery.min.js?v=2.1.4"></script>
<script type="text/javascript">
    $(function() {
        // $.ajax({
        //     url: "/agent/current",
        //     type: "get",
        //     contentType: 'application/json',
        //     success: function (data) {
        //         if(data.code==200){
        //             console.log("已登录");
        //             location.href = "index.html";
        //         }
        //     }
        // });
        $("#soft_username").focus();
        init();
        $("#login").bind('click', function(event) {
            login();
        });

    });
    function rememberPwd(){
        var rememberBox = document.getElementById("remember");
        if (rememberBox.checked) {
            var username = document.getElementById("soft_username").value;
            var password = document.getElementById("soft_password").value;
            addCookie("soft_username",username,200*24);
            addCookie("soft_password",password,200*24);
        }else{
            delCookie("soft_username");
            delCookie("soft_password");
        }
        // login() ;
    }
    function init(){

        var cookie = document.cookie;
        var username = getCookie("soft_username");
        var password = getCookie("soft_password");
        if (username&&password) {
            document.getElementById("soft_username").value=username;
            document.getElementById("soft_password").value=password;
            document.getElementById("remember").checked=true;
        }
    }
    function addCookie(objName,objValue,objHours){//添加cookie
        var str = objName + "=" + escape(objValue);
        if(objHours&&objHours > 0){//为0时不设定过期时间，浏览器关闭时cookie自动消失
            var date = new Date();
            var ms = objHours*3600*1000;
            date.setTime(date.getTime() + ms);
            str += "; expires=" + date.toGMTString()+";path=/";
        }
        document.cookie = str;
    }

    function getCookie(objName){//获取指定名称的cookie的值
        var arrStr = document.cookie.split("; ");
        for(var i = 0;i < arrStr.length;i ++){
            var temp = arrStr[i].split("=");
            if(temp[0] == objName) return unescape(temp[1]);
        }
        return "";
    }

    function delCookie(name){//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
        var date = new Date();
        date.setTime(date.getTime() - 10000);
        var str=""+name+"=a";
        str += "; expires=" + date.toGMTString()+";path=/";
        document.cookie =str;
        // name + "=a; expires=" + date.toGMTString();

    }


    $(document).bind('keydown', function(event) {
        if (event.keyCode == "13") {
            //回车执行查询
            login();
        }
    });

    function login(){

        var userName=$("#soft_username").val();
        var password=$("#soft_password").val();

        if((!userName)||(!password)){
            alert("账号密码不能为空！");
            return;
        }

        rememberPwd();
        $.ajax({
            cache : false,
            dataType : 'json',
            method : 'post',
            contentType:"application/json;charset=UTF-8",
            url : '/agent/login',
            data:JSON.stringify({
                account: userName,
                password: password
            }),
            success : function(response) {
                if(response.code==200){
                    window.location.href = '/index.html';
                }else if(response.code==500){
                    alert("发生错误，原因1："+response.msg);
                } else if(response.code==303){
                    alert("发生错误，原因1："+response.data.msg);
                }
                
                else{
                    alert("发生错误，原因2："+response);
                }
            },
            error:function(e){
                alert("错误:"+JSON.stringify(e));
            }

        });
    }
</script>

</html>
